/**
 * 
 */
package de.cbf.cam.dsa.facet.weapon_ranged.editor;

import static de.cbf.util.ui.test_support.ConstantsSWTBOTUtil.DEFAULT_SWT_BOT_KEY;

import java.util.Arrays;
import java.util.UUID;

import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;

import de.cbf.cam.dsa.facet.weapon_ranged.test_support.ConstantsSWTBOTWeaponRanged;
import de.cbf.util.entity.facet.edit.composites.AbstractCompositeEditFacet;
import de.cbf.util.entity.facet.edit.util.FieldDecoratorUtil;
import de.cbf.util.ui.listener.UiChangeEvent;
import de.cbf.util.ui.swt.util.SWT_Util;

/**
 * @author Nebelritter
 *
 */
public class CompositeEditWeaponRanged extends AbstractCompositeEditFacet {
	
	/** parameter: String[] - selected talent(s)*/
	public static final int CMD_TALENT_SELECTED	= 1;
	public static final int CMD_TALENT_ADD		= 2;
	/** parameter: String[] - selected talent(s) to be removed*/
	public static final int CMD_TALENT_REMOVE	= 3;
	
	public static final int EVT_EDIT_TP						=  1;
	public static final int EVT_EDIT_LOADING_ACTIONS		=  2;
	public static final int EVT_EDIT_RANGE_MIN				=  3;
	public static final int EVT_EDIT_RANGE_VERY_SHORT		=  4;
	public static final int EVT_EDIT_RANGE_SHORT			=  5;
	public static final int EVT_EDIT_RANGE_MEDIUM			=  6;
	public static final int EVT_EDIT_RANGE_LONG				=  7;
	public static final int EVT_EDIT_RANGE_EXTREMELY_LONG 	=  8;
	public static final int EVT_EDIT_DAMAGE_VERY_SHORT		=  9;
	public static final int EVT_EDIT_DAMAGE_SHORT			= 10;
	public static final int EVT_EDIT_DAMAGE_MEDIUM			= 11;
	public static final int EVT_EDIT_DAMAGE_LONG			= 12;
	public static final int EVT_EDIT_DAMAGE_EXTREMELY_LONG 	= 13;	
	
	protected static final String TEXT_GROUP_WEAPON_VALUES		= "Weapon values";
	protected static final String TEXT_GROUP_WEAPON_VALUES_FOR	= "for";
	protected static final String TEXT_GROUP_WEAPON_VALUES_DOTS = "...";
	protected static final String TEXT_GROUP_TALENTS			= "Talents for ranged weapons ...";
	protected static final String TEXT_TALENTS					= "Talents";	
	protected static final String TEXT_ADD_TALENT				= "Add";	
	protected static final String TEXT_REMOVE_TALENT			= "Remove";
	protected static final String TEXT_LABEL_TP					= "Tp: ";
	protected static final String TEXT_LABEL_LOADING_ACTIONS	= "Loading actions: ";
	protected static final String TEXT_LABEL_RANGE_MIN			= "Range(min): ";
	protected static final String TEXT_LABEL_VERY_SHORT			= "very short";
	protected static final String TEXT_LABEL_SHORT				= "short";
	protected static final String TEXT_LABEL_MEDIUM				= "medium";
	protected static final String TEXT_LABEL_LONG				= "long";
	protected static final String TEXT_LABEL_EXTREMELY_LONG 	= "ext.long";
	protected static final String TEXT_LABEL_RANGE				= "Range: ";
	protected static final String TEXT_LABEL_DAMAGE				= "Damage+: ";	
	
	protected static final String TEXT_GROUP_WEAPON_VALUES_DISABLED_HINT = "Please choose/create talent first!";
	
	protected List		li_Talents;
	protected Button	bt_Talents_Add;
	protected Button	bt_Talents_Remove;	
	protected Group		grp_WeaponValues;
	protected Text		tx_Tp;
	protected Text		tx_LoadingActions;
	protected Text		tx_RangeMin;
	protected Text		tx_RangeVeryShort;
	protected Text		tx_RangeShort;
	protected Text		tx_RangeMedium;
	protected Text		tx_RangeLong;
	protected Text		tx_RangeExtremelyLong;
	protected Text		tx_DamageVeryShort;
	protected Text		tx_DamageShort;
	protected Text		tx_DamageMedium;
	protected Text		tx_DamageLong;
	protected Text		tx_DamageExtremelyLong;
			
	protected ControlDecoration decoration_LoadingActions;
	protected ControlDecoration decoration_RangeMin;	
	protected ControlDecoration decoration_RangeVeryShort;
	protected ControlDecoration decoration_RangeShort;
	protected ControlDecoration decoration_RangeMedium;
	protected ControlDecoration decoration_RangeLong;
	protected ControlDecoration decoration_RangeExtremelyLong;
	protected ControlDecoration decoration_DamageVeryShort;
	protected ControlDecoration decoration_DamageShort;
	protected ControlDecoration decoration_DamageMedium;
	protected ControlDecoration decoration_DamageLong;		
	protected ControlDecoration decoration_DamageExtremelyLong;

	public CompositeEditWeaponRanged(Composite parent, int style,FormToolkit toolkit) {
		super(parent, style, toolkit);	
	}
	
	@Override
	protected void adjustInitialUIState() {
		setStatusButtonTalentDeleteEnabled(false);
		setStatusWeaponValuesEnabled(false);
	}
	/* (non-Javadoc)
	 * @see de.cbf.util.entity.facet.edit.composites.AbstractCompositeEditFacet#createLayout()
	 */
	@Override
	protected GridLayout createLayout() {
		GridLayout glo_This = super.createLayout();
		glo_This.numColumns = 1;
		glo_This.makeColumnsEqualWidth = false;
		return glo_This;
	}

	@Override
	protected void createContent(Composite compositeThis) {
		Composite cmp_Talents = createCompositeTalents(compositeThis);
		cmp_Talents.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false,1,1));
		
		Composite cmp_Values = createCompositeWeaponValues(compositeThis);
		cmp_Values.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false,1,1));		
	}
	
	/**
	 * @param parent
	 * @return
	 */
	protected Composite createCompositeTalents(final Composite parent) {
		Group grp_Talents = new Group(parent, SWT.DOUBLE_BUFFERED);
		grp_Talents.setLayout(new GridLayout(2, false));
		grp_Talents.setText(TEXT_GROUP_TALENTS);

		// special two handed
		Label lb_Talents = new Label(grp_Talents, SWT.NONE);
		lb_Talents.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false,2,1));
		lb_Talents.setText(TEXT_TALENTS);

		li_Talents = new List(grp_Talents, SWT.BORDER|SWT.SINGLE);
		GridData gd_Talents = new GridData(SWT.FILL, SWT.FILL, true, false,1,2);
		gd_Talents.heightHint = 30;
		li_Talents.setLayoutData(gd_Talents);
		li_Talents.setData(DEFAULT_SWT_BOT_KEY, ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_LIST_TALENTS_ID);
		li_Talents.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				fireUICommand(CMD_TALENT_SELECTED, (Object[])li_Talents.getSelection());
			}
		});

		bt_Talents_Add = new Button(grp_Talents, SWT.PUSH);
		bt_Talents_Add.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false,1,1));
		bt_Talents_Add.setText(TEXT_ADD_TALENT);
		bt_Talents_Add.setData(DEFAULT_SWT_BOT_KEY, ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_BT_TALENT_ADD_ID);
		bt_Talents_Add.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				fireUICommand(CMD_TALENT_ADD,(Object[])null);
			}
		});

		bt_Talents_Remove = new Button(grp_Talents, SWT.PUSH);
		bt_Talents_Remove.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false,1,1));
		bt_Talents_Remove.setText(TEXT_REMOVE_TALENT);
		bt_Talents_Remove.setData(DEFAULT_SWT_BOT_KEY, ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_BT_TALENT_REMOVE_ID);
		bt_Talents_Remove.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				fireUICommand(CMD_TALENT_REMOVE,(Object[])li_Talents.getSelection());
			}
		});

		return grp_Talents;
	}
	
	protected Composite createCompositeWeaponValues(final Composite parent) {
		grp_WeaponValues = new Group(parent, SWT.DOUBLE_BUFFERED);
		grp_WeaponValues.setLayout(new GridLayout(6, false));
		grp_WeaponValues.setText(TEXT_GROUP_WEAPON_VALUES);		

		//fTp
		Label lb_Tp = toolkit.createLabel(grp_WeaponValues, TEXT_LABEL_TP,SWT.NONE);
		lb_Tp.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
	
		tx_Tp = toolkit.createText(grp_WeaponValues, "",SWT.BORDER);
		tx_Tp.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false,1,1));
		tx_Tp.setData(DEFAULT_SWT_BOT_KEY,ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_TEXT_TP_ID);
		tx_Tp.addModifyListener(new ModifyListener() {
			@Override
			public void modifyText(ModifyEvent e) {
				UiChangeEvent event = new UiChangeEvent(CompositeEditWeaponRanged.this);
				event.setNewValue(tx_Tp.getText());
				event.setIndex(EVT_EDIT_TP);
				fireUIChangeEvent(event);
			}
		});	
		
		//fLoadingActions
		Label lb_LoadingActions = toolkit.createLabel(grp_WeaponValues, TEXT_LABEL_LOADING_ACTIONS,SWT.NONE);
		lb_LoadingActions.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
	
		tx_LoadingActions = toolkit.createText(grp_WeaponValues, "",SWT.BORDER);
		tx_LoadingActions.setLayoutData(new GridData(SWT.LEFT,SWT.FILL,false,false,1,1));
		tx_LoadingActions.setData(DEFAULT_SWT_BOT_KEY,ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_TEXT_LOADING_ACTIONS_ID);
		tx_LoadingActions.addModifyListener(new ModifyListener() {
			@Override
			public void modifyText(ModifyEvent e) {
				UiChangeEvent event = new UiChangeEvent(CompositeEditWeaponRanged.this);
				event.setNewValue(tx_LoadingActions.getText());
				event.setIndex(EVT_EDIT_LOADING_ACTIONS);
				fireUIChangeEvent(event);
			}
		});	
		// Create the decoration for fLoadingActions
		decoration_LoadingActions = new ControlDecoration(tx_LoadingActions,SWT.LEFT|SWT.TOP);
		// Re-use an existing image
		Image image_LoadingActions = FieldDecorationRegistry. getDefault(). getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).
		  getImage();
		// Set description and image
		decoration_LoadingActions.setDescriptionText(FieldDecoratorUtil.TOOLTIP_TEXT_ENTER_NUMBERS_ANY);
		decoration_LoadingActions.setImage(image_LoadingActions);
		decoration_LoadingActions.hide();
		
		//fRangeMin
		Label lb_RangeMin = toolkit.createLabel(grp_WeaponValues, TEXT_LABEL_RANGE_MIN,SWT.NONE);
		lb_RangeMin.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
	
		tx_RangeMin = toolkit.createText(grp_WeaponValues, "",SWT.BORDER);
		tx_RangeMin.setLayoutData(new GridData(SWT.LEFT,SWT.FILL,false,false,1,1));
		tx_RangeMin.setData(DEFAULT_SWT_BOT_KEY,ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_TEXT_RANGE_MIN_ID);
		tx_RangeMin.addModifyListener(new ModifyListener() {			
			@Override
			public void modifyText(ModifyEvent e) {
				UiChangeEvent event = new UiChangeEvent(CompositeEditWeaponRanged.this);
				event.setNewValue(tx_RangeMin.getText());
				event.setIndex(EVT_EDIT_RANGE_MIN);
				fireUIChangeEvent(event);
			}
		});	
		// Create the decoration for fLoadingActions
		decoration_RangeMin = new ControlDecoration(tx_RangeMin,SWT.LEFT|SWT.TOP);
		// Re-use an existing image
		Image image_RangeMin = FieldDecorationRegistry. getDefault(). getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).
		  getImage();
		// Set description and image
		decoration_RangeMin.setDescriptionText(FieldDecoratorUtil.TOOLTIP_TEXT_ENTER_NUMBERS_ANY);
		decoration_RangeMin.setImage(image_RangeMin);
		decoration_RangeMin.hide();
		
		//table like ui for range/damage
		Composite cp_RangeDamage = new Composite(grp_WeaponValues, SWT.DOUBLE_BUFFERED);
			GridLayout glo_RangeDamage = new GridLayout(6,false);
				glo_RangeDamage.marginHeight = 0;
				glo_RangeDamage.marginWidth  = 0;
			cp_RangeDamage.setLayout(glo_RangeDamage);
			cp_RangeDamage.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false,6,1));
	
			//first row
			Label lb_Empty = toolkit.createLabel(cp_RangeDamage, "",SWT.NONE);
			lb_Empty.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
	
			//lb VeryShort
			Label lb_VeryShort = toolkit.createLabel(cp_RangeDamage, TEXT_LABEL_VERY_SHORT,SWT.NONE);
			lb_VeryShort.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
	
			//lb Short
			Label lb_Short = toolkit.createLabel(cp_RangeDamage, TEXT_LABEL_SHORT,SWT.NONE);
			lb_Short.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
			
			//lb Medium
			Label lb_Medium = toolkit.createLabel(cp_RangeDamage, TEXT_LABEL_MEDIUM,SWT.NONE);
			lb_Medium.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
			
			//lb Long
			Label lb_Long = toolkit.createLabel(cp_RangeDamage, TEXT_LABEL_LONG,SWT.NONE);
			lb_Long.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
			
			//lb extremely Long
			Label lb_ExtremelyLong = toolkit.createLabel(cp_RangeDamage, TEXT_LABEL_EXTREMELY_LONG,SWT.NONE);
			lb_ExtremelyLong.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
			
			//second row
			Label lb_Range = toolkit.createLabel(cp_RangeDamage, TEXT_LABEL_RANGE,SWT.NONE);
			lb_Range.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
			
			//fRangeVeryShort
			tx_RangeVeryShort = toolkit.createText(cp_RangeDamage, "",SWT.BORDER);
			tx_RangeVeryShort.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
			tx_RangeVeryShort.setData(DEFAULT_SWT_BOT_KEY,ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_TEXT_RANGE_VERY_SHORT_ID);
			tx_RangeVeryShort.addModifyListener(new ModifyListener() {
				@Override
				public void modifyText(ModifyEvent e) {
					UiChangeEvent event = new UiChangeEvent(CompositeEditWeaponRanged.this);
					event.setNewValue(tx_RangeVeryShort.getText());
					event.setIndex(EVT_EDIT_RANGE_VERY_SHORT);
					fireUIChangeEvent(event);
				}
			});	
			// Create the decoration for fRangeVeryShort
			decoration_RangeVeryShort = new ControlDecoration(tx_RangeVeryShort,SWT.LEFT|SWT.TOP);
			// Re-use an existing image
			Image image_RangeVeryShort = FieldDecorationRegistry. getDefault(). getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).
			  getImage();
			// Set description and image
			decoration_RangeVeryShort.setDescriptionText(FieldDecoratorUtil.TOOLTIP_TEXT_ENTER_NUMBERS_ANY);
			decoration_RangeVeryShort.setImage(image_RangeVeryShort);
			decoration_RangeVeryShort.hide();
				
			//fRangeShort
			tx_RangeShort = toolkit.createText(cp_RangeDamage, "",SWT.BORDER);
			tx_RangeShort.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
			tx_RangeShort.setData(DEFAULT_SWT_BOT_KEY,ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_TEXT_RANGE_SHORT_ID);
			tx_RangeShort.addModifyListener(new ModifyListener() {
				@Override
				public void modifyText(ModifyEvent e) {
					UiChangeEvent event = new UiChangeEvent(CompositeEditWeaponRanged.this);
					event.setNewValue(tx_RangeShort.getText());
					event.setIndex(EVT_EDIT_RANGE_SHORT);
					fireUIChangeEvent(event);
				}
			});	
			// Create the decoration for fRangeShort
			decoration_RangeShort = new ControlDecoration(tx_RangeShort,SWT.LEFT|SWT.TOP);
			// Re-use an existing image
			Image image_RangeShort = FieldDecorationRegistry. getDefault(). getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).
			  getImage();
			// Set description and image
			decoration_RangeShort.setDescriptionText(FieldDecoratorUtil.TOOLTIP_TEXT_ENTER_NUMBERS_ANY);
			decoration_RangeShort.setImage(image_RangeShort);
			decoration_RangeShort.hide();
			
			//fRangeMedium
			tx_RangeMedium = toolkit.createText(cp_RangeDamage, "",SWT.BORDER);
			tx_RangeMedium.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
			tx_RangeMedium.setData(DEFAULT_SWT_BOT_KEY,ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_TEXT_RANGE_MEDIUM_ID);
			tx_RangeMedium.addModifyListener(new ModifyListener() {
				@Override
				public void modifyText(ModifyEvent e) {
					UiChangeEvent event = new UiChangeEvent(CompositeEditWeaponRanged.this);
					event.setNewValue(tx_RangeMedium.getText());
					event.setIndex(EVT_EDIT_RANGE_MEDIUM);
					fireUIChangeEvent(event);
				}
			});	
			// Create the decoration for fRangeMedium
			decoration_RangeMedium = new ControlDecoration(tx_RangeMedium,SWT.LEFT|SWT.TOP);
			// Re-use an existing image
			Image image_RangeMedium = FieldDecorationRegistry. getDefault(). getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).
			  getImage();
			// Set description and image
			decoration_RangeMedium.setDescriptionText(FieldDecoratorUtil.TOOLTIP_TEXT_ENTER_NUMBERS_ANY);
			decoration_RangeMedium.setImage(image_RangeMedium);
			decoration_RangeMedium.hide();
		
			//fRangeLong
			tx_RangeLong = toolkit.createText(cp_RangeDamage, "",SWT.BORDER);
			tx_RangeLong.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
			tx_RangeLong.setData(DEFAULT_SWT_BOT_KEY,ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_TEXT_RANGE_LONG_ID);
			tx_RangeLong.addModifyListener(new ModifyListener() {
				@Override
				public void modifyText(ModifyEvent e) {
					UiChangeEvent event = new UiChangeEvent(CompositeEditWeaponRanged.this);
					event.setNewValue(tx_RangeLong.getText());
					event.setIndex(EVT_EDIT_RANGE_LONG);
					fireUIChangeEvent(event);
				}
			});	
			// Create the decoration for fRangeLong
			decoration_RangeLong = new ControlDecoration(tx_RangeLong,SWT.LEFT|SWT.TOP);
			// Re-use an existing image
			Image image_RangeLong = FieldDecorationRegistry. getDefault(). getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).
			  getImage();
			// Set description and image
			decoration_RangeLong.setDescriptionText(FieldDecoratorUtil.TOOLTIP_TEXT_ENTER_NUMBERS_ANY);
			decoration_RangeLong.setImage(image_RangeLong);
			decoration_RangeLong.hide();
		
			//fRangeExtremelyLong
			tx_RangeExtremelyLong = toolkit.createText(cp_RangeDamage, "",SWT.BORDER);
			tx_RangeExtremelyLong.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
			tx_RangeExtremelyLong.setData(DEFAULT_SWT_BOT_KEY,ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_TEXT_RANGE_EXTREMELY_LONG_ID);
			tx_RangeExtremelyLong.addModifyListener(new ModifyListener() {
				@Override
				public void modifyText(ModifyEvent e) {
					UiChangeEvent event = new UiChangeEvent(CompositeEditWeaponRanged.this);
					event.setNewValue(tx_RangeExtremelyLong.getText());
					event.setIndex(EVT_EDIT_RANGE_EXTREMELY_LONG);
					fireUIChangeEvent(event);
				}
			});	
			
			// Create the decoration for fRangeExtremelyLong
			decoration_RangeExtremelyLong = new ControlDecoration(tx_RangeExtremelyLong,SWT.LEFT|SWT.TOP);
			// Re-use an existing image
			Image image_RangeExtremelyLong = FieldDecorationRegistry. getDefault(). getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).
			  getImage();
			// Set description and image
			decoration_RangeExtremelyLong.setDescriptionText(FieldDecoratorUtil.TOOLTIP_TEXT_ENTER_NUMBERS_ANY);
			decoration_RangeExtremelyLong.setImage(image_RangeExtremelyLong);
			decoration_RangeExtremelyLong.hide();
		
			
			//third row
			Label lb_Damage = toolkit.createLabel(cp_RangeDamage, TEXT_LABEL_DAMAGE,SWT.NONE);
			lb_Damage.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
			//fDamageVeryShort
			tx_DamageVeryShort = toolkit.createText(cp_RangeDamage, "",SWT.BORDER);
			tx_DamageVeryShort.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
			tx_DamageVeryShort.setData(DEFAULT_SWT_BOT_KEY,ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_TEXT_DAMAGE_VERY_SHORT_ID);
			tx_DamageVeryShort.addModifyListener(new ModifyListener() {
				@Override
				public void modifyText(ModifyEvent e) {
					UiChangeEvent event = new UiChangeEvent(CompositeEditWeaponRanged.this);
					event.setNewValue(tx_DamageVeryShort.getText());
					event.setIndex(EVT_EDIT_DAMAGE_VERY_SHORT);
					fireUIChangeEvent(event);
				}
			});	
			// Create the decoration for fDamageVeryShort
			decoration_DamageVeryShort = new ControlDecoration(tx_DamageVeryShort,SWT.LEFT|SWT.TOP);
			// Re-use an existing image
			Image image_DamageVeryShort = FieldDecorationRegistry. getDefault(). getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).
			  getImage();
			// Set description and image
			decoration_DamageVeryShort.setDescriptionText(FieldDecoratorUtil.TOOLTIP_TEXT_ENTER_NUMBERS_ANY);
			decoration_DamageVeryShort.setImage(image_DamageVeryShort);
			decoration_DamageVeryShort.hide();
		
			//fDamageShort
			tx_DamageShort = toolkit.createText(cp_RangeDamage, "",SWT.BORDER);
			tx_DamageShort.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
			tx_DamageShort.setData(DEFAULT_SWT_BOT_KEY,ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_TEXT_DAMAGE_SHORT_ID);
			tx_DamageShort.addModifyListener(new ModifyListener() {
				@Override
				public void modifyText(ModifyEvent e) {
					UiChangeEvent event = new UiChangeEvent(CompositeEditWeaponRanged.this);
					event.setNewValue(tx_DamageShort.getText());
					event.setIndex(EVT_EDIT_DAMAGE_SHORT);
					fireUIChangeEvent(event);
				}
			});	
			// Create the decoration for fDamageShort
			decoration_DamageShort = new ControlDecoration(tx_DamageShort,SWT.LEFT|SWT.TOP);
			// Re-use an existing image
			Image image_DamageShort = FieldDecorationRegistry. getDefault(). getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).
			  getImage();
			// Set description and image
			decoration_DamageShort.setDescriptionText(FieldDecoratorUtil.TOOLTIP_TEXT_ENTER_NUMBERS_ANY);
			decoration_DamageShort.setImage(image_DamageShort);
			decoration_DamageShort.hide();
		
			//fDamageMedium		
			tx_DamageMedium = toolkit.createText(cp_RangeDamage, "",SWT.BORDER);
			tx_DamageMedium.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
			tx_DamageMedium.setData(DEFAULT_SWT_BOT_KEY,ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_TEXT_DAMAGE_MEDIUM_ID);
			tx_DamageMedium.addModifyListener(new ModifyListener() {
				@Override
				public void modifyText(ModifyEvent e) {
					UiChangeEvent event = new UiChangeEvent(CompositeEditWeaponRanged.this);
					event.setNewValue(tx_DamageMedium.getText());
					event.setIndex(EVT_EDIT_DAMAGE_MEDIUM);
					fireUIChangeEvent(event);
				}
			});	
			// Create the decoration for fDamageMedium
			decoration_DamageMedium = new ControlDecoration(tx_DamageMedium,SWT.LEFT|SWT.TOP);
			// Re-use an existing image
			Image image_DamageMedium = FieldDecorationRegistry. getDefault(). getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).
			  getImage();
			// Set description and image
			decoration_DamageMedium.setDescriptionText(FieldDecoratorUtil.TOOLTIP_TEXT_ENTER_NUMBERS_ANY);
			decoration_DamageMedium.setImage(image_DamageMedium);
			decoration_DamageMedium.hide();
		
			//fDamageLong		
			tx_DamageLong = toolkit.createText(cp_RangeDamage, "",SWT.BORDER);
			tx_DamageLong.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
			tx_DamageLong.setData(DEFAULT_SWT_BOT_KEY,ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_TEXT_DAMAGE_LONG_ID);
			tx_DamageLong.addModifyListener(new ModifyListener() {
				@Override
				public void modifyText(ModifyEvent e) {
					UiChangeEvent event = new UiChangeEvent(CompositeEditWeaponRanged.this);
					event.setNewValue(tx_DamageLong.getText());
					event.setIndex(EVT_EDIT_DAMAGE_LONG);
					fireUIChangeEvent(event);
				}
			});	
			// Create the decoration for fDamageLong
			decoration_DamageLong = new ControlDecoration(tx_DamageLong,SWT.LEFT|SWT.TOP);
			// Re-use an existing image
			Image image_DamageLong = FieldDecorationRegistry. getDefault(). getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).
			  getImage();
			// Set description and image
			decoration_DamageLong.setDescriptionText(FieldDecoratorUtil.TOOLTIP_TEXT_ENTER_NUMBERS_ANY);
			decoration_DamageLong.setImage(image_DamageLong);
			decoration_DamageLong.hide();
			
			tx_DamageExtremelyLong = toolkit.createText(cp_RangeDamage, "",SWT.BORDER);
			tx_DamageExtremelyLong.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
			tx_DamageExtremelyLong.setData(DEFAULT_SWT_BOT_KEY,ConstantsSWTBOTWeaponRanged.FACET_WEAPON_RANGED_TEXT_DAMAGE_EXTREMELY_LONG_ID);
			tx_DamageExtremelyLong.addModifyListener(new ModifyListener() {
				@Override
				public void modifyText(ModifyEvent e) {
					UiChangeEvent event = new UiChangeEvent(CompositeEditWeaponRanged.this);
					event.setNewValue(tx_DamageExtremelyLong.getText());
					event.setIndex(EVT_EDIT_DAMAGE_EXTREMELY_LONG);
					fireUIChangeEvent(event);
				}
			});	
					
			// Create the decoration for fDamageExtremelyLong
			decoration_DamageExtremelyLong = new ControlDecoration(tx_DamageExtremelyLong,SWT.LEFT|SWT.TOP);
			// Re-use an existing image
			Image image_DamageExtremelyLong = FieldDecorationRegistry. getDefault(). getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).
			  getImage();
			// Set description and image
			decoration_DamageExtremelyLong.setDescriptionText(FieldDecoratorUtil.TOOLTIP_TEXT_ENTER_NUMBERS_ANY);
			decoration_DamageExtremelyLong.setImage(image_DamageExtremelyLong);
			decoration_DamageExtremelyLong.hide();
		
		return grp_WeaponValues;
	}
	
	public void setStatusButtonTalentDeleteEnabled(boolean enabled){
		if(this.isEnabled()){
			bt_Talents_Remove.setEnabled(enabled);
		}
	}
	
	/**
	 * @param enabled
	 */
	public void setStatusWeaponValuesEnabled(boolean enabled) {
		grp_WeaponValues.setEnabled(enabled);
		SWT_Util.setChildrenEditable(grp_WeaponValues, enabled);
		if( ! enabled){
			grp_WeaponValues.setToolTipText(TEXT_GROUP_WEAPON_VALUES_DISABLED_HINT);
		}else{
			grp_WeaponValues.setToolTipText(null);
		}
	}

	public void setGroupWeaponValuesTalentText(String talentName){
		if(talentName != null && talentName.length() > 0){
			grp_WeaponValues.setText(TEXT_GROUP_WEAPON_VALUES +" "+TEXT_GROUP_WEAPON_VALUES_FOR+" "+talentName);
		}else{
			grp_WeaponValues.setText(TEXT_GROUP_WEAPON_VALUES +TEXT_GROUP_WEAPON_VALUES_DOTS);
		}

	}
	
	public String getSelectedTalentName(){
		String [] selection = li_Talents.getSelection();
		if( selection != null && selection.length > 0){
			return li_Talents.getSelection()[0];
		}
		return null;
	}
	
	public UUID getSelectedTalentUUID(){
		String [] selection = li_Talents.getSelection();
		if( selection != null && selection.length > 0){
			Object selectedData = li_Talents.getData(li_Talents.getSelection()[0]);
			return (UUID)selectedData;
		}
		return null;
	}

	public void setSelectedTalent(String talent){
		//first check if talent that is to be set is already selected
		if(talent != null){
			if(li_Talents.getSelectionCount() > 0 && ! li_Talents.getSelection()[0].equals(talent)){
				//new talent set, select and update text
				for (int i = 0; i < li_Talents.getItems().length; i++) {
					if(li_Talents.getItems()[i].equals(talent)){
						li_Talents.select(i); //will fire events
						return;
					}
				}
			}			
		}
		//talent is not found or null -> erase values of weapon
		setGroupWeaponValuesTalentText(null);
		setStatusWeaponValuesEnabled(false);		
	}

	public String[] getTalents(){
		return li_Talents.getItems();
	}
	
	public void setTalents(String[] talentNames,UUID[] talentUuids){
		if(talentNames != null && ! Arrays.deepEquals(li_Talents.getItems(), talentNames)){			
			String selected = getSelectedTalentName();
			li_Talents.setItems(talentNames);
			for (int i = 0; i < talentNames.length; i++) {
				li_Talents.setData(talentNames[i],talentUuids[i]);
			}
			setSelectedTalent(selected);			
		}
	}

	public void setTp(String value) {
		if( ! tx_Tp.getText().equals(value)){
			tx_Tp.setText(value);
		}
	}
	public void setLoadingActions(String value) {
		if( ! tx_LoadingActions.getText().equals(value)){
			tx_LoadingActions.setText(value);
		}
	}
	
	public void setRangeMin(String value) {
		if( ! tx_RangeMin.getText().equals(value)){
			tx_RangeMin.setText(value);
		}
	}

	public void setRangeVeryShort(String value) {
		if( ! tx_RangeVeryShort.getText().equals(value)){
			tx_RangeVeryShort.setText(value);
		}
	}
	
	public void setRangeShort(String value) {
		if( ! tx_RangeShort.getText().equals(value)){
			tx_RangeShort.setText(value);
		}		
	}
	public void setRangeMedium(String value) {
		if( ! tx_RangeMedium.getText().equals(value)){
			tx_RangeMedium.setText(value);
		}
	}
	public void setRangeLong(String value) {
		if( ! tx_RangeLong.getText().equals(value)){
			tx_RangeLong.setText(value);
		}
	}
	
	public void setRangeExtremelyLong(String value) {
		if( ! tx_RangeExtremelyLong.getText().equals(value)){
			tx_RangeExtremelyLong.setText(value);
		}
	}
	
	public void setDamageVeryShort(String value) {
		if( ! tx_DamageVeryShort.getText().equals(value)){
			tx_DamageVeryShort.setText(value);
		}
	}
	public void setDamageShort(String value) {
		if( ! tx_DamageShort.getText().equals(value)){
			tx_DamageShort.setText(value);
		}
	}
	public void setDamageMedium(String value) {
		if( ! tx_DamageMedium.getText().equals(value)){
			tx_DamageMedium.setText(value);
		}
	}
	public void setDamageLong(String value) {
		if( ! tx_DamageLong.getText().equals(value)){
			tx_DamageLong.setText(value);
		}
	}
	
	public void setDamageExtremelyLong(String value) {
		if( ! tx_DamageExtremelyLong.getText().equals(value)){
			tx_DamageExtremelyLong.setText(value);
		}
	}
	
	public void setDecorationLoadingActionsStatus(boolean active) {
		if(active){
			decoration_LoadingActions.show();
			tx_LoadingActions.setBackground(cl_Text_red);
		}else{
			decoration_LoadingActions.hide();
			tx_LoadingActions.setBackground(cl_Text_list_bg);
		}
	}
	
	public void setDecorationRangeMinStatus(boolean active) {
		if(active){
			decoration_RangeMin.show();
			tx_RangeMin.setBackground(cl_Text_red);
		}else{
			decoration_RangeMin.hide();
			tx_RangeMin.setBackground(cl_Text_list_bg);
		}
	}
	
	public void setDecorationRangeVeryShortStatus(boolean active) {
		if(active){
			decoration_RangeVeryShort.show();
			tx_RangeVeryShort.setBackground(cl_Text_red);
		}else{
			decoration_RangeVeryShort.hide();
			tx_RangeVeryShort.setBackground(cl_Text_list_bg);
		}
	}
	
	public void setDecorationRangeShortStatus(boolean active) {
		if(active){
			decoration_RangeShort.show();
			tx_RangeShort.setBackground(cl_Text_red);
		}else{
			decoration_RangeShort.hide();
			tx_RangeShort.setBackground(cl_Text_list_bg);
		}
	}
		
	public void setDecorationRangeMediumStatus(boolean active) {
		if(active){
			decoration_RangeMedium.show();
			tx_RangeMedium.setBackground(cl_Text_red);
		}else{
			decoration_RangeMedium.hide();
			tx_RangeMedium.setBackground(cl_Text_list_bg);
		}
	}	
	
	public void setDecorationRangeLongStatus(boolean active) {
		if(active){
			decoration_RangeLong.show();
			tx_RangeLong.setBackground(cl_Text_red);
		}else{
			decoration_RangeLong.hide();
			tx_RangeLong.setBackground(cl_Text_list_bg);
		}
	}	
	
	public void setDecorationRangeExtremelyLongStatus(boolean active) {
		if(active){
			decoration_RangeExtremelyLong.show();
			tx_RangeExtremelyLong.setBackground(cl_Text_red);
		}else{
			decoration_RangeExtremelyLong.hide();
			tx_RangeExtremelyLong.setBackground(cl_Text_list_bg);
		}
	}	
	
	public void setDecorationDamageVeryShortStatus(boolean active) {
		if(active){
			decoration_DamageVeryShort.show();
			tx_DamageVeryShort.setBackground(cl_Text_red);
		}else{
			decoration_DamageVeryShort.hide();
			tx_DamageVeryShort.setBackground(cl_Text_list_bg);
		}
	}	
		
	public void setDecorationDamageShortStatus(boolean active) {
		if(active){
			decoration_DamageShort.show();
			tx_DamageShort.setBackground(cl_Text_red);
		}else{
			decoration_DamageShort.hide();
			tx_DamageShort.setBackground(cl_Text_list_bg);
		}
	}	
		
	public void setDecorationDamageMediumStatus(boolean active) {
		if(active){
			decoration_DamageMedium.show();
			tx_DamageMedium.setBackground(cl_Text_red);
		}else{
			decoration_DamageMedium.hide();
			tx_DamageMedium.setBackground(cl_Text_list_bg);
		}
	}	
	
	public void setDecorationDamageLongStatus(boolean active) {
		if(active){
			decoration_DamageLong.show();
			tx_DamageLong.setBackground(cl_Text_red);
		}else{
			decoration_DamageLong.hide();
			tx_DamageLong.setBackground(cl_Text_list_bg);
		}
	}	
	
	public void setDecorationDamageExtremelyLongStatus(boolean active) {
		if(active){
			decoration_DamageExtremelyLong.show();
			tx_DamageExtremelyLong.setBackground(cl_Text_red);
		}else{
			decoration_DamageExtremelyLong.hide();
			tx_DamageExtremelyLong.setBackground(cl_Text_list_bg);
		}
	}

	
	


	

	
}
